package org.example;
public class ControlPanel {
    private static final int MAX_ATTEMPTS = 3;
    private static final int LOCK_TIME = 120;
    private static final String PASSWORD = "1234";

    private enum State {
        READY, LOCKED, FUNCTION_SELECT
    }

    private State state;
    private int attempts;
    private long lockStart;

    public ControlPanel() {
        state = State.READY;
        attempts = 0;
    }

    public void enterPassword(String input) {
        if (state == State.LOCKED) {
            if ((System.currentTime() - lockStart) > LOCK_TIME) {
                state = State.READY;
            } else {
                System.out.println("控制面板已锁定");
                return;
            }
        }

        if (input.equals(PASSWORD)) {
            state = State.FUNCTION_SELECT;
            System.out.println("密码正确，进入系统功能状态");
        } else {
            attempts++;
            if (attempts >= MAX_ATTEMPTS) {
                state = State.LOCKED;
                lockStart = System.currentTimeMillis();
                System.out.println("密码错误，控制面板已锁定");
            } else {
                System.out.println("密码错误，请重新输入");
            }
        }
    }

    public void selectFunction() {
        if (state == State.FUNCTION_SELECT) {
            System.out.println("选择功能");
        } else {
            System.out.println("请先输入密码");
        }
    }
}
